package com.cxyjy.cfyuiapi.service.impl;

import com.cxyjy.cfyuiapi.service.QueryHistoryService;
import com.cxyjy.cfyuiapi.service.ViewService;
import com.cxyjy.common.util.JObjectUtil;
import com.cxyjy.common.util.JRequestUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.net.URL;

import static com.cxyjy.common.constants.CfyuiConstants.HISTORY_URL;

@Service("QueryHistoryService")
public class QueryHistoryServiceImpl implements QueryHistoryService {
    @Autowired
    ViewService viewService;


    /**
     * 如果promptId不为空，则发送请求：
     * GET /history/{prompt_id}
     * GET /history/8b918008-751f-414c-9575-7174e841ceac
     * 获取历史任务数据(根据任务id获取历史数据)
     * <p>
     * 如果promptId为空，则GET /history
     * GET /history
     * 获取所有历史任务数据
     *
     * @param promptId
     * @return
     * @throws IOException
     */
    @Override
    public Object queryhistory(String promptId) throws IOException {
        URL url;
        if (JObjectUtil.isNotEmpty(promptId)) {
            url = new URL(JObjectUtil.stringValue(HISTORY_URL) + "/" + promptId);
        } else {
            url = HISTORY_URL;
        }
        Object data = JRequestUtil.sendGetRequest(url, null);
        return data;
    }

}
